"""
admin应用的URL配置
@file admin/urls.py
@description admin后台相关URL路由
@created 2024-04-08
"""
from django.urls import path
from . import views
from . import teacher_views
from . import teacher_admin  # 导入新的teacher_admin模块
from . import user_admin # 确保导入的是更新后的user_admin

# admin端URL路由
urlpatterns = [
    # 测试数据库连接
    path('test-db/', views.test_db_connection, name='test_db_connection'),
    
    # 管理员认证相关接口
    path('api/auth/admin/login/', views.admin_login, name='admin_login'),
    path('api/auth/admin/info/', views.admin_info, name='admin_info'),
    path('api/auth/admin/logout/', views.admin_logout, name='admin_logout'),
    path('api/auth/refresh/', views.refresh_token, name='refresh_token'),
    
    # --- 新的用户管理 API (原生SQL) ---
    path('admin/user/list', user_admin.list_users_api, name='admin_list_users_api'),
    path('admin/user/list/', user_admin.list_users_api, name='admin_list_users_api_slash'),
    path('admin/user/add', user_admin.add_user_api, name='admin_add_user_api'),
    path('admin/user/update/<int:user_id>', user_admin.update_user_api, name='admin_update_user_api'),
    path('admin/user/delete/<int:user_id>', user_admin.delete_user_api, name='admin_delete_user_api'),
    path('admin/user/reset-password/<int:user_id>', user_admin.reset_password_api, name='admin_reset_password_api'),
    path('admin/user/toggle-status/<int:user_id>', user_admin.toggle_user_status_api, name='admin_toggle_user_status_api'),
    
    # --- 学院和班级列表 API (原生SQL) ---
    path('admin/colleges/list', user_admin.list_colleges_api, name='admin_list_colleges_api'),
    path('admin/colleges/list/', user_admin.list_colleges_api, name='admin_list_colleges_api_slash'),
    path('admin/colleges/<int:college_id>/classes', user_admin.list_classes_by_college_api, name='admin_list_classes_by_college_api'),

    # --- 保留旧的用户管理路径 (注释掉，因为已被新的API取代) ---
    # path('api/admin/users/', user_admin.user_list, name='user_list'),
    # path('api/admin/users/<int:user_id>/', user_admin.user_detail, name='user_detail'),
    # path('api/admin/users/permissions/', user_admin.get_user_permissions, name='get_user_permissions'),
    
    # --- 保留旧的学院管理相关接口 (如果它们仍在使用或由views.py处理其他逻辑) ---
    # 如果这些与新的原生SQL API冲突或重复，应评估是否需要保留或移除
    path('api/colleges/', views.college_list, name='college_list'), # 可能与 user_admin.list_colleges_api 冲突，取决于主路由的包含方式
    path('api/colleges/<int:college_id>/', views.college_detail, name='college_detail'),
    # path('api/colleges/<int:college_id>/classes/', views.college_classes, name='college_classes'), # 与 user_admin.list_classes_by_college_api 冲突
    path('api/colleges/<int:college_id>/grades/<int:grade_id>/classes/<int:class_id>/', views.class_detail, name='class_detail'),
    path('api/colleges/<int:college_id>/grades/<int:grade_id>/classes/<int:class_id>/students/', views.class_students, name='class_students'),
    path('api/colleges/<int:college_id>/grades/<int:grade_id>/classes/<int:class_id>/analysis/<str:analysis_type>/', views.class_analysis, name='class_analysis'),
    path('api/colleges/<int:college_id>/grades/<int:grade_id>/classes/<int:class_id>/students/<str:student_id>/learning/', views.class_student_learning, name='class_student_learning'),
    
    # YZH表格API接口
    path('api/admin/colleges/list/', teacher_admin.yzh_college_list, name='yzh_college_list'), # 注意：此路径与上面的 user_admin.list_colleges_api 相同。Django会匹配第一个。
    path('api/admin/colleges/<int:college_id>/departments/', teacher_admin.yzh_department_list, name='yzh_department_list'),
    path('api/admin/yzh_teachers/list/', teacher_admin.yzh_teacher_list, name='yzh_teacher_list'),
    path('api/admin/yzh_teachers/<str:teacher_id>/', teacher_admin.yzh_teacher_detail, name='yzh_teacher_detail'),
    path('api/admin/yzh_teachers/add/', teacher_admin.yzh_add_teacher, name='yzh_add_teacher'),
    path('api/admin/yzh_teachers/update/<str:teacher_id>/', teacher_admin.yzh_update_teacher, name='yzh_update_teacher'),
    path('api/admin/yzh_teachers/delete/<str:teacher_id>/', teacher_admin.yzh_delete_teacher, name='yzh_delete_teacher'),
    path('api/admin/yzh_teachers/<str:teacher_id>/courses/', teacher_admin.yzh_teacher_courses, name='yzh_teacher_courses'),
    path('api/admin/yzh_teachers/<str:teacher_id>/courses/<int:course_id>/classes/', teacher_admin.yzh_teacher_course_classes, name='yzh_teacher_course_classes'),
    path('api/admin/yzh_teachers/<str:teacher_id>/courses/<int:course_id>/classes/<int:class_id>/students/', teacher_admin.yzh_class_student_scores, name='yzh_class_student_scores'),

    # 新增：yzh_college 单个详情 和 yzh_college 下的班级列表
    path('api/admin/yzh_colleges/<int:college_id>/detail/', teacher_admin.yzh_college_detail_view, name='yzh_college_detail_view'),
    path('api/admin/yzh_colleges/<int:college_id>/classes/', teacher_admin.yzh_college_classes_view, name='yzh_college_classes_view'), # 注意：此路径与上面的 user_admin.list_classes_by_college_api 相同
    
    # 新增：yzh_class 单个详情 和 yzh_class 下的学生列表
    path('api/admin/yzh_classes/<int:class_id>/detail/', teacher_admin.yzh_class_detail_view, name='yzh_class_detail_view'),
    path('api/admin/yzh_classes/<int:class_id>/students/', teacher_admin.yzh_class_students_view, name='yzh_class_students_view'),
    
    # 新增：班级增删改查接口
    path('api/admin/yzh_classes/add/', teacher_admin.yzh_add_class, name='yzh_add_class'),
    path('api/admin/yzh_classes/list/', teacher_admin.yzh_class_list, name='yzh_class_list'),
    path('api/admin/yzh_classes/update/<int:class_id>/', teacher_admin.yzh_update_class, name='yzh_update_class'),
    path('api/admin/yzh_classes/delete/<int:class_id>/', teacher_admin.yzh_delete_class, name='yzh_delete_class'),
    
    # 新增：班级学生增删改查接口
    path('api/admin/yzh_students/add/', teacher_admin.yzh_add_student, name='yzh_add_student'),
    path('api/admin/yzh_students/<int:student_id>/', teacher_admin.yzh_student_detail, name='yzh_student_detail'),
    path('api/admin/yzh_students/update/<int:student_id>/', teacher_admin.yzh_update_student, name='yzh_update_student'),
    path('api/admin/yzh_students/delete/<int:student_id>/', teacher_admin.yzh_delete_student, name='yzh_delete_student'),
    
    # 学生管理相关接口
    # 注释掉找不到的视图函数
    # path('api/students/', views.student_list, name='student_list'),
    path('api/students/<str:student_id>/', views.student_detail, name='student_detail'),
    path('api/students/<int:student_id>/attendance/', views.student_attendance, name='student_attendance'),
    path('api/students/<int:student_id>/courses/', views.student_courses, name='student_courses'),
    
    # AI功能相关接口
    path('api/admin/ai/classify-document/', views.ai_classify_document, name='ai_classify_document'),
    path('api/admin/ai/evaluate-quality/', views.ai_evaluate_quality, name='ai_evaluate_quality'),
    path('api/admin/ai/recommendations/', views.ai_get_recommendations, name='ai_get_recommendations'),
    path('api/admin/ai/optimize-format/', views.ai_optimize_format, name='ai_optimize_format'),
    path('api/admin/ai/dify-message/', views.ai_dify_message, name='ai_dify_message'),
    path('api/admin/ai/upload-to-knowledge-base/', views.ai_upload_to_knowledge_base, name='ai_upload_to_knowledge_base'),
    
    # 智能交互式帮助系统API接口
    path('api/admin/dify/chat-completion', views.dify_chat_completion, name='dify_chat_completion'),
    path('api/admin/dify/stream-chat', views.dify_stream_chat, name='dify_stream_chat'),
    path('api/admin/dify/apps', views.dify_get_apps, name='dify_get_apps'),
    path('api/admin/dify/frequent-questions', views.dify_frequent_questions, name='dify_frequent_questions'),
    path('api/admin/dify/context-questions', views.dify_context_questions, name='dify_context_questions'),
    path('api/admin/dify/feedback', views.dify_feedback, name='dify_feedback'),
    path('api/admin/dify/test-connection', views.test_dify_connection, name='test_dify_connection'),
    path('api/admin/dify/proxy', views.dify_cors_proxy, name='dify_cors_proxy'),
    
    # AI决策系统API接口
    path('api/admin/ai/anomaly-detection/', views.ai_anomaly_detection, name='ai_anomaly_detection'),
    path('api/admin/ai/prediction/<str:prediction_type>/', views.ai_prediction, name='ai_prediction'),
    path('api/admin/ai/recommendations/<str:category>/', views.ai_recommendations, name='ai_recommendations'),
    path('api/admin/ai/recommendation-feedback/', views.ai_recommendation_feedback, name='ai_recommendation_feedback'),
    path('api/admin/ai/analyze-teaching-data/', views.ai_analyze_teaching_data, name='ai_analyze_teaching_data'),
    path('api/admin/ai/nl-query/', views.ai_nl_query, name='ai_nl_query'),
    path('api/admin/ai/teaching-quality/', views.ai_teaching_quality, name='ai_teaching_quality'),
    path('api/admin/ai/resource-optimization/', views.ai_resource_optimization, name='ai_resource_optimization'),
    path('api/admin/ai/test-decision-connection/', views.test_decision_connection, name='test_decision_connection'),
    
    # 测试API - 用于特定调试目的
    path('api/test/student/20230101026/', views.test_student_detail, name='test_student_detail'),
    
    # 动态测试API - 可处理任意学生ID的测试接口
    path('api/test/dynamic-student/<str:student_id>/', views.dynamic_student_detail, name='dynamic_student_detail'),
    
    # 资源管理相关接口
    path('api/admin/resource/upload/', views.resource_upload, name='resource_upload'),
    path('api/admin/resource/list/', views.resource_list, name='resource_list'),
    path('api/admin/resource/detail/<int:resource_id>/', views.resource_detail, name='resource_detail'),
    path('api/admin/resource/delete/<int:resource_id>/', views.resource_delete, name='resource_delete'),
    
    # 教师发展系统API接口
    path('api/admin/teacher-development/', views.teacher_development_system, name='teacher_development_system'),
    path('api/admin/teacher/list/', views.teacher_list, name='teacher_list'),
    path('api/admin/teacher/detail/<str:teacher_id>/', views.teacher_detail, name='teacher_detail'),
    path('api/admin/teacher/teaching-effectiveness/<str:teacher_id>/', views.teacher_effectiveness, name='teacher_effectiveness'),
    path('api/admin/teacher/training-recommendations/<str:teacher_id>/', views.teacher_training_recommendations, name='teacher_training_recommendations'),
    path('api/admin/teacher/collaboration-recommendations/<str:teacher_id>/', views.teacher_collaboration_recommendations, name='teacher_collaboration_recommendations'),
    path('api/admin/teacher/resource-recommendations/', views.teacher_resource_recommendations, name='teacher_resource_recommendations'),
    path('api/admin/teacher/test-connection/', teacher_views.test_connection, name='teacher_test_connection'),
    
    # 添加新的教师管理API路由 - 使用teacher_admin模块中的函数
    path('api/admin/teacher/add/', teacher_admin.add_teacher, name='add_teacher'),
    path('api/admin/teacher/update/<str:teacher_id>/', teacher_admin.update_teacher, name='update_teacher'),
    path('api/admin/teacher/delete/<str:teacher_id>/', teacher_admin.delete_teacher, name='delete_teacher'),
    path('api/admin/teacher/batch-delete/', teacher_admin.batch_delete_teachers, name='batch_delete_teachers'),
    path('api/admin/teacher/import/', teacher_admin.import_teachers, name='import_teachers'),
    path('api/admin/teacher/export/', teacher_admin.export_teachers, name='export_teachers'),
    
    # 教师课程和班级相关API
    path('api/admin/teachers/<str:teacher_id>/courses/', teacher_views.teacher_courses, name='teacher_courses'),
    path('api/admin/teachers/<str:teacher_id>/courses/<str:course_id>/classes/<str:class_id>/students/', teacher_views.class_students_scores, name='class_students_scores'),
    path('api/admin/teacher/delete/<int:teacher_id>/', teacher_admin.yzh_delete_teacher, name='yzh_delete_teacher'), # Redundant with above delete?
    path('api/admin/teacher/<int:teacher_id>/courses/', teacher_admin.yzh_teacher_courses, name='yzh_teacher_courses'),
] 

